package com.itany.netclass.util;

import com.itany.netclass.exception.MD5ErrorException;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Author:sjy@itany.com
 * Date:2021/9/16 16:23
 * Version:1.0-SNAPSHOT
 */
public class MD5Util {

    public static String md5(String s){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(s.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(b);
        } catch (NoSuchAlgorithmException e) {
            throw new MD5ErrorException("MD5加密出错");
        }
    }

}
